#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;

  int ordy = 9999, ordm = 13, ordd = 32;

  for (int i = 1; i <= n; i++) {
    char _;
    int y, m, d;
    cin >> y >> _ >> m >> _ >> d;
    if (y < ordy || y == ordy && m < ordm ||
        y == ordy && m == ordm && d < ordd) {
      ordy = y;
      ordm = m;
      ordd = d;
    }
  }

  cout << ordy << "-";

  if (ordm < 10)
    cout << 0;
  cout << ordm << "-";
  
  if (ordd < 10)
    cout << 0;
  cout << ordd;

  return 0;
}